<template>
  <div id="link-group">
    <el-form inline style="margin: 0px;padding: 0px">
      <el-form-item v-for="(button,index) of validateButtons" :key="index" style="margin: 0px;padding: 0px">
        <el-link @click="handleClick(button.index)" v-if="button.button.buttonType==2" :icon="button.button.icon" :type="button.button.buttonColor">{{button.button.name}}</el-link>
        <el-button @click="handleClick(button.index)" v-if="button.button.buttonType==1" :icon="button.button.icon" :type="button.button.buttonColor">{{button.button.name}}</el-button>
        <el-divider direction="vertical" v-if="index < validateButtons.length-1"></el-divider>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    
    name: "link-group",
    
    props:{
      buttons:{
        type:Array
      },
      data:{
        type:Object,
        default(){
          return {}
        }
      }
    },
    
    components: {},
    data() {
      return {
        validateButtons:[],
      }
    },
    watch: {},
    methods: {
      handleClick(index){
        let content={
          index:index,
          data:this.data
        }
        console.log('index',index)
        this.$emit('handleClick',content)
      },
      initButton(){
        this.$nextTick(()=>{
          for (let i = 0; i < this.buttons.length; i++) {
            let button =  this.buttons[i]
            if (button.havePermission && button.isShow == 1){
              let item = {
                index:i,
                button:button
              }
              this.$set(this.validateButtons,this.validateButtons.length,item)
            }
          }
        })

      }
    },
    mounted() {
      this.initButton()
    }
  }
</script>

<style scoped>

</style>
